package cn.djb.day11;

import cn.djb.day2.ListNode;

import java.util.ArrayList;
import java.util.List;

class Solution_2 {

    public ListNode getKthFromEnd(ListNode head, int k) {

        List<ListNode> list = new ArrayList<>();
        list.add(head);
        ListNode tmp = head;
        while (tmp.next != null) {
            list.add(tmp.next);
            tmp = tmp.next;
        }
        int size = list.size();
        if (size >= k) {
            return list.get(size - k);
        }

        return null;

    }

}